//
//  EvDetailsViewController.m
//  Manage
//
//  Created by 杨康 on 2017/11/11.
//  Copyright © 2017年 杨康. All rights reserved.
//

#import "EvDetailsViewController.h"
#import "DeviceDetail.h"
@interface EvDetailsViewController ()
{
    YKTextField *_nameTF;
    YKTextField *_plateTF;
    YKTextField *_storeTF;
    YKTextField *_brandTF;
    YKTextField *_modelTF;
    YKTextField *_colorTF;
    YKTextField *_frameTF;
    YKTextField *_motorTF;
    UITextView *_textView;
}
@property(nonatomic,strong)ykTableView *tableView;
@property(nonatomic,strong)UIView *reasonView;
@property(nonatomic,strong)UIView *reasonView2;
@end

@implementation EvDetailsViewController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self getCarDetailInfo];
}
-(void)getCarDetailInfo
{
    NSString *URLString = @"/axq/admin/device/get";
    NSDictionary *parameters = @{@"deviceid": self.deviceid};
    [NetworkPath requestWithMethod:0 andURLString:URLString andParameters:parameters RequestSuccess:^(NSURLResponse *response, id responseObject) {
        NSLog(@"%@",responseObject);
        NSString *code=[NetworkPath getValue:@"code" from:responseObject];
        if (code.length) {
            if([code isEqualToString:@"10008"])
            {
             
                if ([NetworkPath isDictionary:@"data" from:responseObject]) {

                    
                    
                    DeviceDetail *model=[DeviceDetail modelWithDict:responseObject[@"data"]];
                    _nameTF.text=model.devicename;
                    _plateTF.text=model.platenumber;
                    _storeTF.text=model.shopname;
                    _brandTF.text=model.brandname;
                    _modelTF.text=model.model;
                    _colorTF.text=model.color;
                    _frameTF.text=model.vinnumber;
                    _motorTF.text=model.motornumber;
                    _textView.text=model.dis;
                    self.tableView.className=@"Type2";
                    NSMutableArray *itemArr=[NSMutableArray array];
                    
                    cellData *dataObj=[[cellData alloc]init];
                    dataObj.image=@"物业";
                    dataObj.text=@"物业";
                    dataObj.detailText=model.propertyname;
                    
                    cellData *dataObj2=[[cellData alloc]init];
                    dataObj2.image=@"民警";
                    dataObj2.text=@"民警";
                    dataObj2.detailText=model.policename;
                    
                    cellData *dataObj3=[[cellData alloc]init];
                    dataObj3.image=@"电动车厂商";
                    dataObj3.text=@"电动车厂商";
                    dataObj3.detailText=model.producername;
                    
                    
                    [itemArr addObject:dataObj];
                    [itemArr addObject:dataObj2];
                    [itemArr addObject:dataObj3];
                    
                    
                    [self.tableView.dataArray addObject:itemArr];
                    [self.tableView reloadData];
                     for (UIView* subView in self.view.subviews)
                     {
                         if ([subView isKindOfClass:[YKButton class]]) {
                             
                             YKButton *secButton=(YKButton *)subView;
                             NSURL *babyUrl;
                             switch (secButton.tag) {
                                 case 1000:
                                     babyUrl=[NSURL URLWithString:model.img1];
                                     break;
                                 case 2000:
                                     babyUrl=[NSURL URLWithString:model.img2];
                                     break;
                                 case 3000:
                                     babyUrl=[NSURL URLWithString:model.img3];
                                     break;
                                 case 4000:
                                     babyUrl=[NSURL URLWithString:model.img4];
                                     break;
                                 case 5000:
                                     babyUrl=[NSURL URLWithString:model.img5];
                                     break;
                                 case 6000:
                                     babyUrl=[NSURL URLWithString:model.img6];
                                     break;
                                 case 7000:
                                     babyUrl=[NSURL URLWithString:model.img7];
                                     break;
                                 case 8000:
                                     babyUrl=[NSURL URLWithString:model.img8];
                                     break;
                                 case 9000:
                                     babyUrl=[NSURL URLWithString:model.img9];
                                     break;
                                     
                                 default:
                                     break;
                             }
                             
                             
                             
                             UIImage *babyImage=[UIImage imageNamed:@"添加图片"];
                             
                             
                             [secButton.imageView sd_setImageWithURL:babyUrl placeholderImage:babyImage completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                                 [secButton setBackgroundImage:secButton.imageView.image forState:UIControlStateNormal];
                             }];
                         }
                     }
                    
                    
                    
                }
                
                
            }else
            {
                NSString *str=[NetworkPath getValue:@"msg" from:responseObject];
                
                [self.view makeToast:str];
            }
        }
        
    } RequestFailed:^(NSError *error) {
        
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"电动车详情";
    
    UIButton *leftButton=(UIButton *)self.navigationItem.leftBarButtonItem.customView;
    leftButton.selected=YES;
    
    
    
    UIScrollView *myScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, TOP_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT-TOP_HEIGHT)];
    myScrollView.contentSize=CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT-TOP_HEIGHT+800);
    myScrollView.showsVerticalScrollIndicator = NO;
    myScrollView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:myScrollView];
    
    if (@available(iOS 11.0,*)) {
        
        myScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else
    {
        
    }
    
    
    
    
    //电动车名称
    YKTextField *nameTF=[SingLeton myTextFieldsecure:NO andkeyboardType:UIKeyboardTypeDefault andplaceholder:@"请输入电动车名称" andLeftImage:@"电动车名称" RequestSuccess:^(YKTextField *textField, NSRange range, NSString *string) {
        
    }];
    [myScrollView addSubview:nameTF];
    
    [nameTF mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 44));
    }];
    _nameTF=nameTF;
    
    
    //车牌号
    YKTextField *plateTF=[SingLeton myTextFieldsecure:NO andkeyboardType:UIKeyboardTypeDefault andplaceholder:@"请输入车牌号" andLeftImage:@"车牌号" RequestSuccess:^(YKTextField *textField, NSRange range, NSString *string) {
        
    }];
    [myScrollView addSubview:plateTF];
    
    [plateTF mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.mas_equalTo(nameTF.mas_bottom).mas_offset(1);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 44));
    }];
    _plateTF=plateTF;
    
    
    
    //门店
    YKTextField *storeTF=[SingLeton myTextFieldsecure:NO andkeyboardType:UIKeyboardTypeDefault andplaceholder:@"请选择门店" andLeftImage:@"门店" RequestSuccess:^(YKTextField *textField, NSRange range, NSString *string) {

    }];
    UIImageView *image=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"右箭头"]];
    storeTF.rightView=image;
    storeTF.rightViewMode = UITextFieldViewModeAlways;
    [myScrollView addSubview:storeTF];

    [storeTF mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(plateTF.mas_bottom).mas_offset(1);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 44));
    }];
    _storeTF=storeTF;




    //电动车品牌
    YKTextField *brandTF=[SingLeton myTextFieldsecure:NO andkeyboardType:UIKeyboardTypeDefault andplaceholder:@"请选择电动车品牌" andLeftImage:@"小电动车品牌" RequestSuccess:^(YKTextField *textField, NSRange range, NSString *string) {

    }];
    UIImageView *image2=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"右箭头"]];
    brandTF.rightView=image2;
    brandTF.rightViewMode = UITextFieldViewModeAlways;
    [myScrollView addSubview:brandTF];

    [brandTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(storeTF.mas_bottom).mas_offset(1);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 44));
    }];
    _brandTF=brandTF;



    //型号
    YKTextField *modelTF=[SingLeton myTextFieldsecure:NO andkeyboardType:UIKeyboardTypeDefault andplaceholder:@"请选择型号" andLeftImage:@"型号" RequestSuccess:^(YKTextField *textField, NSRange range, NSString *string) {

    }];
    UIImageView *image3=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"右箭头"]];
    modelTF.rightView=image3;
    modelTF.rightViewMode = UITextFieldViewModeAlways;
    [myScrollView addSubview:modelTF];

    [modelTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(brandTF.mas_bottom).mas_offset(1);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 44));
    }];
    _modelTF=modelTF;


    //颜色
    YKTextField *colorTF=[SingLeton myTextFieldsecure:NO andkeyboardType:UIKeyboardTypeDefault andplaceholder:@"请选择颜色" andLeftImage:@"颜色" RequestSuccess:^(YKTextField *textField, NSRange range, NSString *string) {

    }];
    UIImageView *image4=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"右箭头"]];
    colorTF.rightView=image4;
    colorTF.rightViewMode = UITextFieldViewModeAlways;
    [myScrollView addSubview:colorTF];

    [colorTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(modelTF.mas_bottom).mas_offset(1);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 44));
    }];
    _colorTF=colorTF;



    //车架号
    YKTextField *frameTF=[SingLeton myTextFieldsecure:NO andkeyboardType:UIKeyboardTypeDefault andplaceholder:@"请输入车架号" andLeftImage:@"车架号" RequestSuccess:^(YKTextField *textField, NSRange range, NSString *string) {

    }];
    [myScrollView addSubview:frameTF];

    [frameTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(colorTF.mas_bottom).mas_offset(1);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 44));
    }];
    _frameTF=frameTF;
    

    //电机号
    YKTextField *motorTF=[SingLeton myTextFieldsecure:NO andkeyboardType:UIKeyboardTypeDefault andplaceholder:@"请输入电机号" andLeftImage:@"电机号" RequestSuccess:^(YKTextField *textField, NSRange range, NSString *string) {

    }];
    [myScrollView addSubview:motorTF];

    [motorTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(frameTF.mas_bottom).mas_offset(1);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 44));
    }];
    _motorTF=motorTF;
    
    
    
    
    //描述
    UIView *describeView=[[UIView alloc]init];
    [myScrollView addSubview:describeView] ;
    [describeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(motorTF.mas_bottom).mas_offset(1);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 100));
    }];
    describeView.backgroundColor=[UIColor whiteColor];
    
    UIImageView *describeImg=[[UIImageView alloc]init];
    [describeView addSubview:describeImg];
    [describeImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.mas_equalTo(describeView.mas_top).mas_offset(22);
    }];
    
    describeImg.image=[UIImage imageNamed:@"个性化描述"];
    
    
    UITextView *textView = [[UITextView alloc] init];
    [describeView addSubview:textView];
    [textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(describeImg.mas_right).mas_offset(10);
        make.top.mas_equalTo(7);
        
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-25-describeImg.bounds.size.width, 100-7));
    }];
    textView.textColor = [UIColor color6];
    textView.backgroundColor = [UIColor whiteColor];
    
    
    
    //必要条件font
    textView.font = [UIFont systemFontOfSize:14];
    //设置placeholder
    UILabel *placeHolderLabel = [[UILabel alloc] init];
    placeHolderLabel.text = @"请输入电动车个性化描述信息";
    placeHolderLabel.font = [UIFont systemFontOfSize:14];
    placeHolderLabel.textColor = [UIColor colorWithRed:0 green:0 blue:0.1 alpha:0.22];
    [textView addSubview:placeHolderLabel];
    [textView setValue:placeHolderLabel forKey:@"_placeholderLabel"];
    _textView=textView;
    
    //车子照片
    UIView *carPhotoView=[[UIView alloc]init];
    [myScrollView addSubview:carPhotoView];
    [carPhotoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(describeView.mas_bottom).mas_offset(1);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 105));
    }];
    carPhotoView.backgroundColor=[UIColor whiteColor];
    
    UIImageView *carImageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"电动车名称"]];
    [carPhotoView addSubview:carImageView];
    [carImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(10);
        
    }];
    
    UILabel *carLab=[[UILabel alloc]init];
    [carPhotoView addSubview:carLab];
    [carLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(carImageView.mas_right).mas_offset(10);
        make.centerY.mas_equalTo(carImageView);
    }];
    carLab.text=@"车子照片";
    carLab.textColor=[UIColor color3];
    carLab.font=[UIFont systemFontOfSize:14.0];
    
    
    for (int i=0; i<3; i++) {
        YKButton *carButton=[SingLeton endButton:[UIColor whiteColor] andTitle:nil RequestSuccess:^(UIButton *btn) {
            [SingLeton PhotoAction:self RequestSuccess:^(UIImagePickerController *picker, NSDictionary<NSString *,id> *info) {
                //选择
                if (info) {
                    
                    UIImage* image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
                    [btn setBackgroundImage:image forState:UIControlStateNormal];
                    
                }
                //取消
                else
                {
                    
                }
            }];
        }];
        [carPhotoView addSubview:carButton];
        [carButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(carLab.mas_left).mas_offset(65*i);
            make.top.mas_equalTo(carLab.mas_bottom).mas_offset(15);
            make.size.mas_equalTo(CGSizeMake(50, 50));
        }];
        carButton.layer.cornerRadius=0;
        [carButton setBackgroundImage:[UIImage imageNamed:@"添加图片"] forState:UIControlStateNormal];
        carButton.tag=(i+1)*1000;
        
    }
    
    //发票照片
    UIView *invoiceView=[[UIView alloc]init];
    [myScrollView addSubview:invoiceView];
    [invoiceView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(carPhotoView.mas_bottom).mas_offset(1);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 105));
    }];
    invoiceView.backgroundColor=[UIColor whiteColor];
    
    UIImageView *invoiceImageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"发票"]];
    [invoiceView addSubview:invoiceImageView];
    [invoiceImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(10);
        
    }];
    
    UILabel *invoiceLab=[[UILabel alloc]init];
    [invoiceView addSubview:invoiceLab];
    [invoiceLab mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.mas_equalTo(invoiceImageView.mas_right).mas_offset(10);
        make.centerY.mas_equalTo(invoiceImageView);
    }];
    invoiceLab.text=@"发票照片";
    invoiceLab.textColor=[UIColor color3];
    invoiceLab.font=[UIFont systemFontOfSize:14.0];
    
    
    for (int i=0; i<3; i++) {
        YKButton *invoiceButton=[SingLeton endButton:[UIColor whiteColor] andTitle:nil RequestSuccess:^(UIButton *btn) {
            [SingLeton PhotoAction:self RequestSuccess:^(UIImagePickerController *picker, NSDictionary<NSString *,id> *info) {
                //选择
                if (info) {
                    
                    UIImage* image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
                    [btn setBackgroundImage:image forState:UIControlStateNormal];
                    
                }
                //取消
                else
                {
                    
                }
            }];
        }];
        [invoiceView addSubview:invoiceButton];
        [invoiceButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(invoiceLab.mas_left).mas_offset(65*i);
            make.top.mas_equalTo(invoiceLab.mas_bottom).mas_offset(15);
            make.size.mas_equalTo(CGSizeMake(50, 50));
        }];
        invoiceButton.layer.cornerRadius=0;
        [invoiceButton setBackgroundImage:[UIImage imageNamed:@"添加图片"] forState:UIControlStateNormal];
        invoiceButton.tag=(i+1)*1000;
        
    }
    
    
    //个性化照片
    UIView *uniqueView=[[UIView alloc]init];
    [myScrollView addSubview:uniqueView];
    [uniqueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(invoiceView.mas_bottom).mas_offset(1);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 105));
    }];
    uniqueView.backgroundColor=[UIColor whiteColor];
    
    UIImageView *uniqueImageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"个性化照片"]];
    [uniqueView addSubview:uniqueImageView];
    [uniqueImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(10);
        
    }];
    
    UILabel *uniqueLab=[[UILabel alloc]init];
    [uniqueView addSubview:uniqueLab];
    [uniqueLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(uniqueImageView.mas_right).mas_offset(10);
        make.centerY.mas_equalTo(uniqueImageView);
    }];
    uniqueLab.text=@"个性化照片";
    uniqueLab.textColor=[UIColor color3];
    uniqueLab.font=[UIFont systemFontOfSize:14.0];
    
    
    for (int i=0; i<3; i++) {
        YKButton *uniqueButton=[SingLeton endButton:[UIColor whiteColor] andTitle:nil RequestSuccess:^(UIButton *btn) {
            [SingLeton PhotoAction:self RequestSuccess:^(UIImagePickerController *picker, NSDictionary<NSString *,id> *info) {
                //选择
                if (info) {
                    
                    UIImage* image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
                    [btn setBackgroundImage:image forState:UIControlStateNormal];
                    
                }
                //取消
                else
                {
                    
                }
            }];
        }];
        [uniqueView addSubview:uniqueButton];
        [uniqueButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(uniqueLab.mas_left).mas_offset(65*i);
            make.top.mas_equalTo(uniqueLab.mas_bottom).mas_offset(15);
            make.size.mas_equalTo(CGSizeMake(50, 50));
        }];
        uniqueButton.layer.cornerRadius=0;
        [uniqueButton setBackgroundImage:[UIImage imageNamed:@"添加图片"] forState:UIControlStateNormal];
        uniqueButton.tag=(i+1)*1000;
        
    }
    

//    UILabel *userLab=[[UILabel alloc]init];
//    [myScrollView addSubview:userLab];
//    [userLab mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(15);
//        make.top.mas_equalTo(uniqueView.mas_bottom);
//        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-15, 50));
//    }];
//    userLab.text=@"所属用户";
//    userLab.textColor=[UIColor color9];
//    userLab.font=[UIFont systemFontOfSize:14];
//    userLab.textAlignment=NSTextAlignmentLeft;
//
//
//    //真实姓名
//    YKTextField *userNameTF=[SingLeton myTextFieldsecure:NO andkeyboardType:UIKeyboardTypeDefault andplaceholder:@"请输入真实姓名" andLeftImage:@"姓名" RequestSuccess:^(YKTextField *textField, NSRange range, NSString *string) {
//
//    }];
//    [myScrollView addSubview:userNameTF];
//
//    [userNameTF mas_makeConstraints:^(MASConstraintMaker *make) {
//
//        make.top.mas_equalTo(userLab.mas_bottom);
//        make.left.mas_equalTo(0);
//        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 44));
//    }];
//
//    //身份证号
//    YKTextField *idNumTF=[SingLeton myTextFieldsecure:NO andkeyboardType:UIKeyboardTypeDefault andplaceholder:@"请输入身份证号" andLeftImage:@"身份证号" RequestSuccess:^(YKTextField *textField, NSRange range, NSString *string) {
//
//    }];
//    [myScrollView addSubview:idNumTF];
//
//    [idNumTF mas_makeConstraints:^(MASConstraintMaker *make) {
//
//        make.top.mas_equalTo(userNameTF.mas_bottom).mas_offset(1);
//        make.left.mas_equalTo(0);
//        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 44));
//    }];
//
//    //手机号
//    YKTextField *phoneTF=[SingLeton myTextFieldsecure:NO andkeyboardType:UIKeyboardTypeDefault andplaceholder:@"请输入手机号" andLeftImage:@"姓名" RequestSuccess:^(YKTextField *textField, NSRange range, NSString *string) {
//
//    }];
//    [myScrollView addSubview:phoneTF];
//
//    [phoneTF mas_makeConstraints:^(MASConstraintMaker *make) {
//
//        make.top.mas_equalTo(idNumTF.mas_bottom).mas_offset(1);
//        make.left.mas_equalTo(0);
//        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 44));
//    }];
    
    self.tableView=[SingLeton myTableViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44*3) withRefresh:NO didSelect:^(ykTableView *tableView, NSIndexPath *indexPath) {
        
    }];
    [myScrollView addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
//        make.top.mas_equalTo(phoneTF.mas_bottom).mas_offset(15);
        make.top.mas_equalTo(uniqueView.mas_bottom).mas_offset(15);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 44*3));
    }];
    
    
    
    self.tableView.className=@"Type2";
    NSMutableArray *itemArr=[NSMutableArray array];
    
    cellData *dataObj=[[cellData alloc]init];
    dataObj.image=@"物业";
    dataObj.text=@"物业";
    dataObj.detailText=@"物业名称";
    
    cellData *dataObj2=[[cellData alloc]init];
    dataObj2.image=@"民警";
    dataObj2.text=@"民警";
    dataObj2.detailText=@"民警";
    
    cellData *dataObj3=[[cellData alloc]init];
    dataObj3.image=@"电动车厂商";
    dataObj3.text=@"电动车厂商";
    dataObj3.detailText=@"电动车厂商";
    
    
    [itemArr addObject:dataObj];
    [itemArr addObject:dataObj2];
    [itemArr addObject:dataObj3];
    
    
    [self.tableView.dataArray addObject:itemArr];
    [self.tableView reloadData];
    
    
    
    YKButton *agreeButton=[SingLeton endButton:[UIColor colorQ] andTitle:@"审核通过" RequestSuccess:^(UIButton *btn) {
        UIAlertController *alertController=[UIAlertController alertControllerWithTitle:@"审核通过" message:@"确定审核通过吗?" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *noAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        UIAlertAction *someAction=[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self passAction];
        }];
        
        
        [alertController addAction:noAction];
        [alertController addAction:someAction];
        [self presentViewController:alertController animated:YES completion:nil];
        [noAction setValue:[UIColor color3] forKey:@"titleTextColor"];
    }];
    [myScrollView addSubview:agreeButton];
    [agreeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(self.tableView.mas_bottom).mas_offset(15);
        make.size.mas_equalTo(CGSizeMake((SCREEN_WIDTH-55)/2, 44));
        
    }];
    
    YKButton *refuseButton=[SingLeton endButton:[UIColor colorI] andTitle:@"审核不通过" RequestSuccess:^(UIButton *btn) {
        self.reasonView.hidden=NO;
        [self refuseAction];

        
    }];
    [myScrollView addSubview:refuseButton];
    [refuseButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(agreeButton.mas_right).mas_offset(15);
        make.top.mas_equalTo(agreeButton);
        make.size.mas_equalTo(CGSizeMake((SCREEN_WIDTH-55)/2, 44));
        
    }];
    
    if ([self.type isEqualToString:@"未审核"]) {
        
    }
    else if ([self.type isEqualToString:@"已审核"])
    {
        agreeButton.hidden=YES;
        refuseButton.hidden=YES;
    }
    else if ([self.type isEqualToString:@"未通过"])
    {
        agreeButton.hidden=YES;
        refuseButton.hidden=YES;
        //右按钮
        UIButton *rightButton=[NetworkPath SetNavRightBtnWithController:self withTitle:nil andImageName:@"疑问"];
        [rightButton addTarget:self action:@selector(refuseReason) forControlEvents:UIControlEventTouchUpInside];
    }else
    {
        agreeButton.hidden=YES;
        refuseButton.hidden=YES;
        
        UIView *headView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44+10)];
        
        
        
        
        YKTextField *stateTF=[SingLeton myTextFieldsecure:NO andkeyboardType:UIKeyboardTypeDefault andplaceholder:nil andLeftImage:@"车辆状态" RequestSuccess:^(YKTextField *textField, NSRange range, NSString *string) {
            
        }];
        
        stateTF.text=@"车辆状态";
        stateTF.font=[UIFont systemFontOfSize:13];
        stateTF.enabled=NO;
        [headView addSubview:stateTF];
        [stateTF mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.and.top.mas_equalTo(0);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 44));
            
        }];
        
        
        UILabel *stateLab=[[UILabel alloc]init];
        [stateTF addSubview:stateLab];
        [stateLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-15);
            make.centerY.mas_equalTo(stateTF);
            
            
        }];
        stateLab.text=@"报失中";
        stateLab.textColor=[stateLab.text isEqualToString:@"报失中"]?[UIColor colorI]:[UIColor colorQ];
        stateLab.font=[UIFont systemFontOfSize:12];
        self.tableView.tableHeaderView=headView;
        [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 44*3+54));
        }];
//        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.mas_equalTo(0);
//            make.top.mas_equalTo(phoneTF.mas_bottom).mas_offset(15);
//
//        }];
        
    }
    
    
    
    
}
-(void)passAction
{
    NSString *URLString = [NSString stringWithFormat:@"/axq/admin/device/audit/%@",self.deviceid];
//    NSDictionary *parameters = @{@"id": @""};
    [NetworkPath requestWithMethod:0 andURLString:URLString andParameters:nil RequestSuccess:^(NSURLResponse *response, id responseObject) {
        NSLog(@"%@",responseObject);
        NSString *code=[NetworkPath getValue:@"code" from:responseObject];
        if (code.length) {
            if([code isEqualToString:@"10008"])
            {
                [self.navigationController popViewControllerAnimated:YES];
            }else
            {
                NSString *str=[NetworkPath getValue:@"msg" from:responseObject];
                
                [self.view makeToast:str];
            }
        }
        
    } RequestFailed:^(NSError *error) {
        
    }];
}
-(void)refuseAction
{
    NSString *URLString = [NSString stringWithFormat:@"/axq/admin/device/unaudit/%@",self.deviceid];
//    NSDictionary *parameters = @{@"peopletel": @""};
    [NetworkPath requestWithMethod:0 andURLString:URLString andParameters:nil RequestSuccess:^(NSURLResponse *response, id responseObject) {
        NSLog(@"%@",responseObject);
        NSString *code=[NetworkPath getValue:@"code" from:responseObject];
        if (code.length) {
            if([code isEqualToString:@"10008"])
            {
              [self.navigationController popViewControllerAnimated:YES];
            }else
            {
                NSString *str=[NetworkPath getValue:@"msg" from:responseObject];
                
                [self.view makeToast:str];
            }
        }
        
    } RequestFailed:^(NSError *error) {
        
    }];
}
-(void)refuseReason
{
  self.reasonView2.hidden=NO;
}
-(UIView *)reasonView2
{
    
    if (!_reasonView2) {
        UIView *bgView=[[UIView alloc]initWithFrame:self.view.frame];
        bgView.backgroundColor=[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.2];
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideCurrentVC:)];
        [bgView addGestureRecognizer:tap];
        
        
        
        UIView *myView=[[UIView alloc]init];
        [bgView addSubview:myView];
        [myView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.mas_equalTo(bgView);
            make.size.mas_equalTo(CGSizeMake(220, 44+1+10+30*3+10));
        }];
        myView.backgroundColor=[UIColor whiteColor];
        myView.layer.masksToBounds=YES;
        myView.layer.cornerRadius=5.0;
        
        
        UILabel *titleLab=[[UILabel alloc]init];
        [myView addSubview:titleLab];
        [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(myView);
            make.top.mas_equalTo(0);
            make.size.mas_equalTo(CGSizeMake(220, 44));
        }];
        titleLab.text=@"选择不通过原因";
        titleLab.textColor=[UIColor colorI];
        titleLab.textAlignment=NSTextAlignmentCenter;
        
        UILabel *lineLab=[[UILabel alloc]init];
        [myView addSubview:lineLab];
        [lineLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(20);
            make.top.mas_equalTo(titleLab.mas_bottom);
            make.size.mas_equalTo(CGSizeMake(180, 1));
        }];
        lineLab.backgroundColor=[UIColor colorE];
        NSArray *reasonArr=[NSArray arrayWithObjects:@"1.车子照片不清晰", @"2.发票照片不清晰",@"3.个性化照片不清晰",nil];
        for (int i=0; i<3; i++) {
            YKButton *reasonButton=[SingLeton endButton:[UIColor whiteColor] andTitle:reasonArr[i] RequestSuccess:^(UIButton *btn) {
                btn.selected=!btn.selected;
            }];
            [myView addSubview:reasonButton];
            [reasonButton mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(20);
                make.top.mas_equalTo(lineLab.mas_bottom).mas_offset(10+30*i);
                
            }];
            reasonButton.titleLabel.font=[UIFont systemFontOfSize:14];
            [reasonButton setTitleColor:[UIColor color6] forState:UIControlStateNormal];
            
            
            
        }
        
        
        
        [self.view.window addSubview:_reasonView2=bgView];
        
    }
    
    return _reasonView2;
}
-(UIView *)reasonView
{
    
    if (!_reasonView) {
    UIView *bgView=[[UIView alloc]initWithFrame:self.view.frame];
        bgView.backgroundColor=[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.2];
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideCurrentVC:)];
    [bgView addGestureRecognizer:tap];
        
    
    
    UIView *myView=[[UIView alloc]init];
    [bgView addSubview:myView];
    [myView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.mas_equalTo(bgView);
            make.size.mas_equalTo(CGSizeMake(220, 200));
        }];
    myView.backgroundColor=[UIColor whiteColor];
    myView.layer.masksToBounds=YES;
    myView.layer.cornerRadius=5.0;
    
    
    UILabel *titleLab=[[UILabel alloc]init];
    [myView addSubview:titleLab];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(myView);
        make.top.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(220, 44));
    }];
    titleLab.text=@"选择不通过原因";
    titleLab.textColor=[UIColor colorI];
        titleLab.textAlignment=NSTextAlignmentCenter;
    
    UILabel *lineLab=[[UILabel alloc]init];
    [myView addSubview:lineLab];
    [lineLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(titleLab.mas_bottom);
        make.size.mas_equalTo(CGSizeMake(180, 1));
    }];
    lineLab.backgroundColor=[UIColor colorE];
    NSArray *reasonArr=[NSArray arrayWithObjects:@"  车子照片不清晰", @"  发票照片不清晰",@"  个性化照片不清晰",nil];
    for (int i=0; i<3; i++) {
        YKButton *reasonButton=[SingLeton endButton:[UIColor whiteColor] andTitle:reasonArr[i] RequestSuccess:^(UIButton *btn) {
            btn.selected=!btn.selected;
        }];
        [myView addSubview:reasonButton];
        [reasonButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(20);
        make.top.mas_equalTo(lineLab.mas_bottom).mas_offset(10+30*i);

        }];
        reasonButton.titleLabel.font=[UIFont systemFontOfSize:14];
        [reasonButton setTitleColor:[UIColor color6] forState:UIControlStateNormal];
        [reasonButton setImage:[UIImage imageNamed:@"未选择"] forState:UIControlStateNormal];
        [reasonButton setImage:[UIImage imageNamed:@"选择"] forState:UIControlStateSelected];
        
        
    }
        YKButton *submitButton=[SingLeton endButton:[UIColor colorQ] andTitle:@"提交" RequestSuccess:^(UIButton *btn) {
            self.reasonView.hidden=YES;
        }];
        [myView addSubview:submitButton];
        [submitButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(myView);
            make.top.mas_equalTo(lineLab.mas_bottom).mas_offset(110);
            make.size.mas_equalTo(CGSizeMake(150, 30));
            
        }];
        
        
        [self.view.window addSubview:_reasonView=bgView];

    }
    
    return _reasonView;
}
-(void)hideCurrentVC:(UIGestureRecognizer *)tap{
    if ([self.type isEqualToString:@"未审核"]) {
      self.reasonView.hidden=YES;
    }else
    {
        self.reasonView2.hidden=YES;
    }
    
    

}
@end
